/**
 * Created by macbookair on 2019/5/9.
 */


$(function () {

    var aid = $('.heartimg').attr('aid');
    $('.heartimg').attr("src", "../../../images/白心.png");

    $.ajax({
        type:'GET',
        url:'/cl/Lovestatus?aid='+aid,
        success:function (data) {
            console.log("lalalalala")
            //1表示当前为点赞，2表示取消了点赞
            if (data.msg == 'like'){
                $(".heartimg").attr("src", "../../../images/红心.png");
            }else {
                $(".heartimg").attr("src", "../../../images/白心.png");
            }
        }

    })


    $('.heartimg').on('click',function () {
        var aid = $('.heartimg').attr('aid');
        console.log(aid);
        $.ajax({
                type: 'POST',
                url: '/cl/AriStar?aid='+aid,
                success:function (data) {
                    console.log(data.msg);
                    //1表示当前为点赞，2表示取消了点赞
                    if (data.msg == 'like'){

                        $('.heartimg').attr("src", "../../../images/红心.png");
                        var likenums = $('.likenum').html();
                        var newlikenum= parseInt(likenums)+1;
                        $('.likenum').html(newlikenum);
                    }else {
                        $('.heartimg').attr("src", "../../../images/白心.png");
                        var likenums = $('.likenum').html();
                        var newlikenum= parseInt(likenums)-1;
                        $('.likenum').html(newlikenum);
                    }
                }
            })


    })



})




